package com.EAIPClub.UserAuthDataManager.mapper;

import com.api.POJO.UserAuthDataManager.UserAuthData;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description :用户登录信息管理模块Mapper
 * @Author :崔昌赫
 * @Date : 2021/10/20
 */

@Mapper
@Repository
public interface UserAuthDataManagerMapper {
    @Select("SELECT * FROM userauth WHERE 1=1")
    List<UserAuthData> getAllUserAuthData();
    @Select("SELECT * FROM userauth WHERE uid='${uid}'")
    UserAuthData getUserAuthDataByUid(@Param("uid")String uid);
    @Select("SELECT * FROM userauth WHERE token='${token}'")
    UserAuthData getUserAuthDataByToken(@Param("token")String token);
    @Select("SELECT * FROM userauth WHERE date='${date}'")
    List<UserAuthData> getUserAuthDataByDate(@Param("date") String date);
    @Select("SELECT * FROM userauth WHERE expiration='${expiration}'")
    List<UserAuthData> getUserAuthDataByExpiration(@Param("expiration")String expiration);

    @Insert("INSERT INTO userauth values('${authdata.uid}','${authdata.token}','${authdata.date}','${authdata.expiration}')")
    Boolean addNewUserAuthData(@Param("authdata")UserAuthData authData);

    @Update("UPDATE userauth SET uid='${authdata.uid}',token='${authdata.token}',date='${authdata.date}',expiration='${authdata.expiration}' WHERE uid='${uid}'")
    Boolean updateUserAuthDataByUid(@Param("uid")String uid,@Param("authdata")UserAuthData authData);
    @Update("UPDATE userauth SET uid='${authdata.uid}',token='${authdata.token}',date='${authdata.date}',expiration='${authdata.expiration}' WHERE token='${token}'")
    Boolean updateUserAuthDataByToken(@Param("token")String token,@Param("authdata")UserAuthData authData);
    @Update("UPDATE userauth SET uid='${authdata.uid}',token='${authdata.token}',date='${authdata.date}',expiration='${authdata.expiration}' WHERE date='${date}'")
    Boolean updateUserAuthDataByDate(@Param("date")String date,@Param("authdata")UserAuthData authData);
    @Update("UPDATE userauth SET uid='${authdata.uid}',token='${authdata.token}',date='${authdata.date}',expiration='${authdata.expiration}' WHERE expiration='${expiration}'")
    Boolean updateUserAuthDataByExpiration(@Param("expiration")String expiration,@Param("authdata")UserAuthData authData);

    @Delete("DELETE FROM userauth WHERE uid='${uid}'")
    Boolean deleteUserAuthDataByUid(@Param("uid")String uid);
    @Delete("DELETE FROM userauth WHERE token='${token}'")
    Boolean deleteUserAuthDataByToken(@Param("token")String token);
    @Delete("DELETE FROM userauth WHERE date='${date}'")
    Boolean deleteUserAuthDataByDate(@Param("date")String date);
    @Delete("DELETE FROM userauth WHERE expiration='${expiration}'")
    Boolean deleteUserAuthDataByExpiration(@Param("expiration")String expiration);

}
